package com.lzxuni.modules.qualitycomplaints;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.lzxuni.common.utils.R;
import com.lzxuni.common.utils.StringUtils;
import com.lzxuni.common.utils.UuidUtil;
import com.lzxuni.modules.common.controller.BaseController;
import com.lzxuni.modules.common.entity.FileEntity;
import com.lzxuni.modules.common.entity.PageData;
import com.lzxuni.modules.common.entity.PageParameter;
import com.lzxuni.modules.common.service.FileEntityService;
import com.lzxuni.modules.enterprise.entity.EnterpriseInfo;
import com.lzxuni.modules.enterprise.service.EnterpriseInfoService;
import com.lzxuni.modules.organization.entity.Company;
import com.lzxuni.modules.productdisplay.entity.ProductDisplay;
import com.lzxuni.modules.productdisplay.service.ProductDisplayService;
import com.lzxuni.modules.qualitycomplaints.entity.QualityComplaints;
import com.lzxuni.modules.qualitycomplaints.service.QualityComplaintsService;
import com.lzxuni.modules.system.entity.Editor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 质量投诉 前端控制器
 * </p>
 *
 * @author 杨国营
 * @since 2019-07-09
 */
@RestController
@RequestMapping("/LR_QualityComplaints")
public class QualityComplaintsController extends BaseController {
	//质量投诉
	@Autowired
	private QualityComplaintsService qualityComplaintsService;

	//保存附件使用
	@Autowired
	private FileEntityService fileEntityService;

	//质量投诉列表
	@RequestMapping("/Index")
	public ModelAndView list() {
		ModelAndView mv = new ModelAndView("/LR_QualityComplaints/index");
		return mv;
	}
	@RequestMapping("/GetList")
	public Object GetList(String pagination,String keyword) throws Exception {
		//1.Json转换成实体类
		PageParameter pageParameter = JSON.parseObject(pagination, PageParameter.class);
		//调用父类的一个方法，传进一个参数pageParameter进行查询操作将在业务层将结果直接封装进PageInfo中然后将PageInfo数据封装进pageData中，返回到页面中
		PageInfo<QualityComplaints> pageInfo = qualityComplaintsService.queryPage(pageParameter, keyword);
		for (QualityComplaints qualityComplaints : pageInfo.getList()) {
			FileEntity fileEntity = new FileEntity();
			fileEntity.setYwId(qualityComplaints.getId());
			fileEntity.setYwType("ZLTS");
			fileEntity.setType("ZLTSGL");
			List<FileEntity> fileEntityList =  fileEntityService.queryListByFileEntity(fileEntity);
			qualityComplaints.setFileEntityList(fileEntityList);
		}
		PageData pageData = getPageData(pageInfo);
		return R.ok().put("data", pageData);
	}

	//反馈页面
	@RequestMapping("/Form")
	public ModelAndView insert(String parentId){
		ModelAndView mv = new ModelAndView("/LR_QualityComplaints/form");
		return mv;
	}
	//富文本编辑器回显
	@RequestMapping("GetEntity")
	public Object  GetEntity(String keyValue) {
		QualityComplaints qualityComplaints = qualityComplaintsService.getById(keyValue);
		return R.ok().put("data", qualityComplaints);
	}
	//添加反馈内容
	@RequestMapping("/SaveForm")
	public Object saveForm(QualityComplaints qualityComplaints) throws Exception {
		qualityComplaints.setIsanswer("是");
		qualityComplaintsService.updateById(qualityComplaints);
		return R.ok("反馈成功！");
	}



}

